//
//  TestMenuView.m
//  sandbox
//
//  Created by 杨岑 on 6/26/15.
//  Copyright (c) 2015 杨岑. All rights reserved.
//

#import "TestMenuVC.h"
#import "NSMutableAttributedString+Ext.h"


@interface TestMenuVC ()
@property (unsafe_unretained) IBOutlet NSTextView *textview;
@property (weak) IBOutlet NSTextField *label;

@end

@implementation TestMenuVC

- (void)awakeFromNib
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(frameDidChange:) name:NSViewFrameDidChangeNotification object:nil];
    
    self.textview.postsBoundsChangedNotifications = YES;

    //NSRect rect = self.view.bounds;
    //self.textview = [[NSTextView alloc] initWithFrame:NSMakeRect(0, rect.size.height - 30, rect.size.width, 30)];
    //[self.view addSubview:self.textview];
    
    self.textview.drawsBackground = NO;
    self.textview.editable = YES;
    //self.textview.backgroundColor = [NSColor whiteColor];
    self.textview.textColor = [NSColor blueColor];
    NSMutableAttributedString *link = [NSMutableAttributedString hyperlinkFromString:@"apple.com\na\nb\nc\nd\n***" withURL:[NSURL URLWithString:@"http://www.apple.com"]];
    [self.textview.textStorage setAttributedString:link];
    //self.textview.alphaValue = .8;
}

- (void)frameDidChange:(NSNotification*)notification
{
    static CGFloat lastH;
    
    CGFloat h = self.textview.bounds.size.height;
    if (lastH != h)
    {
        NSLog(@"%@ new height: %f", self, h);
        self.view.frame = NSMakeRect(0, 0, self.view.bounds.size.width, h);
        lastH = h;
    }
}

- (IBAction)test_click:(id)sender {
    NSRect bounds = NSMakeRect(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 10);
    self.view.frame = bounds;
    self.label.stringValue = @"test1\ntest2\ntest3\nxxx";
}


@end
